/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mb.webserver.handler;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import mb.config.Constants;
import mb.config.ConstantsMsg;
import mb.mbmiddle.MbPartMiddle;
import mb.mbpart.memory.BaseMemory;
import mb.webserver.inMemory.ListFunctionProcess;
import mb.webserver.inMemory.MBServerConfigProcess;

/**
 *
 * @author thanh.nguyenchi
 */
public class ListFunction extends BaseServlet{   
    private String fileSeparator;
    private String functionFile;
    
    public ListFunction(){
        super(); 
        fileSeparator = System.getProperty("file.separator");
        functionFile = System.getProperty("user.dir") + fileSeparator + Constants.STR_WEBSERVER_ROOT;
        functionFile = functionFile + fileSeparator + Constants.STR_WEBSERVER_DATA;
        //functionFile = functionFile + fileSeparator + Constants.STR_WEBSERVER_FUNCTION;
    }
    
    @Override
    public void doGet(HttpServletRequest request,HttpServletResponse response)
        throws ServletException,IOException
    {                  
        String lang             = request.getParameter("lang");                 // log
        String callback         = request.getParameter("callback");             // check 
        
        String sOut = ""; 
        String sFile = "";       
        
        // call bussiness
        ListFunctionProcess objProcess = new ListFunctionProcess(lang);
        if ((callback != null) && (callback.length() >= 4)){
            sOut = callback + "(" + objProcess.getResult() + ")";
        }
        else{
            // return no callback
            sOut = objProcess.getResult();
        }                
        
        response.setContentType("application/json; charset=UTF-8"); 
        response.setStatus(HttpServletResponse.SC_OK);
        response.getWriter().println(sOut);
    }    
    
}
